package com.item.controller;


import com.item.bean.Result;
import com.item.domain.TbUser;
import com.item.domain.TbUserCommentInit;
import com.item.dto.CommentDto;
import com.item.po.TbUserCommentInitPo;
import com.item.service.TbUserCommentInitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class TbUserCommentInitController {

    @Autowired
    TbUserCommentInitService tbUserCommentInitService;

    @PostMapping(value = "/tbUserCommentInit/{limit}/{page}")
    public Result TbUserCommentInit(
            @PathVariable(value = "limit", required = false) int limit,
            @PathVariable(value = "page", required = false) int page,
            @RequestBody(required = false) TbUserCommentInit tbUserCommentInit) {
        Result result = new Result();

        List<TbUserCommentInit> tbUserCommentInits = tbUserCommentInitService.findAll(limit, page, tbUserCommentInit);

        if (tbUserCommentInits != null) {
            result.setFlag(true);
            result.setMessage("数据请求成功");
            result.setData(tbUserCommentInits);
        } else {
            result.setFlag(false);
            result.setMessage("数据请求失败");
            result.setData(new ArrayList<>());
        }

        return result;
    }

    @PostMapping(value = "/tbUserCommentInit/to/list/add")
    public Integer TbUserCommentInitAdd(@RequestBody TbUserCommentInit tbUserCommentInit) {
        tbUserCommentInit.setCreateTime(System.currentTimeMillis() + "");
        int i = tbUserCommentInitService.add(tbUserCommentInit);
        return i;
    }

    @PutMapping(value = "/tbUserCommentInit/to/list/update")
    public Integer tbUserCommentInitUpdate(@RequestBody TbUserCommentInit tbUserCommentInit) {

        int i = tbUserCommentInitService.update(tbUserCommentInit);
        return i;
    }

    @DeleteMapping(value = "/tbUserCommentInit/{id}")
    public Integer tbUserCommentInitDelete(@PathVariable(value = "id") int id) {

        int i = tbUserCommentInitService.delete(id);
        return i;
    }

    @PostMapping(value = "/tbUserCommentInit/status")
    public Integer TbUserStatusAdd(@RequestBody CommentDto commentDto) {

        int i = tbUserCommentInitService.statusAdd(commentDto);
        return i;
    }

    /***
     * 二级评论
     * @param
     * @return
     */
    @PostMapping(value = "/tbUserCommentInit/status/leven")
    public Integer TbUserStatusAddLeven(@RequestBody TbUserCommentInit commentDto) {
        commentDto.setCreateTime(System.currentTimeMillis() + "");
        int i = tbUserCommentInitService.statusAddLeven(commentDto);
        return i;
    }

    @GetMapping(value = "/tbUserCommentInit/commentlist/{id}")
    public List<TbUserCommentInitPo> tbUserCommentInitGet(@PathVariable(value = "id") int id) {

        return tbUserCommentInitService.tbUserCommentInitGet(id);

    }

    @PostMapping(value = "/tbUserCommentInit/comment")
    public List<TbUserCommentInitPo> tbUserCommentInitPos(@RequestBody TbUserCommentInitPo tbUserCommentInitPo) {

        return tbUserCommentInitService.tbUserCommentInitPos(tbUserCommentInitPo);
    }

}
